package com.slz3.business.module.goodsManagement.gooInventory.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.slz3.business.frame.enums.AuditFlag;
import com.slz3.business.frame.enums.UsingFlag;
import com.slz3.business.frame.functions.Add;
import com.slz3.business.frame.functions.Modify;
import com.slz3.business.frame.module.DomainEntity;
import com.slz3.business.module.goodsManagement.gooInventory.enums.GooInventoryGoodsType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.time.LocalDate;
import java.util.UUID;

import static javax.persistence.EnumType.STRING;

@MappedSuperclass
@Data
@EqualsAndHashCode(callSuper = false)
public class GooInventoryEntity extends DomainEntity {

    /**
     * 编号
     */
    @Column(length = 80)
    @Null(message = "编号 必须为空!", groups = {Add.class})
//    @NotNull(message = "serNum 必须非空!", groups = {Add.class, Modify.class})
//    @Length(min = 1, max = 80, message = "ser2 必须非空并且不超过 80 个字符!", groups = {Add.class, Modify.class})
    private String serNum;

    /**
     * 备注
     */
    @Basic(fetch = FetchType.LAZY)
    @Type(type = "text")
    private String serMemo;

    /**
     * 审核状态
     */
    @Enumerated(STRING)
    @NotNull(message = "serAudit 必须非空!", groups = {Add.class})
    @Null(message = "serAudit 必须为空!", groups = {Modify.class})
    private AuditFlag serAudit;

    //    /**
//     * 启用状态
//     */
    @Enumerated(STRING)
//    @NotNull(message = "serUsing 必须非空!", groups = {Add.class})
//    @Null(message = "serUsing 必须为空!", groups = {Modify.class})
    private UsingFlag serUsing;

    /**
     * 标签
     */
    private String serLabels;

    //    /**
//     * 文件 url 地址
//     */
    private String serFileUrl;

    /**
     * 富文本编辑器内容
     */
    @Basic(fetch = FetchType.LAZY)
    @Column(columnDefinition = "TEXT")
    private String serEditorContent;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private LocalDate serInputGroupData;

    // 枚举 - 商品类型
    @Enumerated(STRING)
    @NotNull(message = "商品类型 必须非空!", groups = {Add.class, Modify.class})
    private GooInventoryGoodsType enumGoodsType;

    // 关联商品
    @NotNull(message = "关联商品 必须非空!", groups = {Add.class, Modify.class})
    private UUID fkGoods;
    private String goodsName; // 冗余

    // 库存增量
    @NotNull(message = "库存增量 必须非空!", groups = {Add.class, Modify.class})
    private Long serAmount;

    // 当前库存总数
    @Null(message = "当前库存总数 必须为空!", groups = {Add.class, Modify.class})
    private Long serAmountCurrentTotal;

}
